package com.monitor.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.monitor.entity.ErpTirePolice;

/**
 * <p>
 * 轮胎报警表 Mapper 接口
 * </p>
 *
 * @author LX
 * @since 2018-09-12
 */
public interface ErpTirePoliceMapper extends BaseMapper<ErpTirePolice> {
	//获取车辆报警类别
	@Select("SELECT police_type FROM erp_tire_police WHERE car_id=#{carId} AND tire_location=#{position} AND solve_dt=NULL order by id limit 0,1")
	public Integer selectPoliceType(@Param("carId")int carId,@Param("position")String position);
	
	//统计分析
	@Select("SELECT * from erp_tire_police t, erp_customer c, erp_customer_car cc 	where t.plate = cc.car_plate 		and t.solve_dt is not null 		and ( t.police_type = 5 or t.police_type = 6 ) 		and t.police_dt >= #{startTime} 	and t.police_dt < #{endTime} 		and cc.customer_id = c.id 	and ( c.cus_code = #{code} or c.cus_service_com like #{code} ) limit #{page},#{limit}")
	public List<Map<String, Object>> selectTong(@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("code")String code,@Param("page")int page,@Param("limit")int limit);
	
	@Select("SELECT count(1) from erp_tire_police t, erp_customer c, erp_customer_car cc 	where t.plate = cc.car_plate 		and t.solve_dt is not null 		and ( t.police_type = 5 or t.police_type = 6 ) 		and t.police_dt >= #{startTime} 	and t.police_dt < #{endTime} 		and cc.customer_id = c.id 	and ( c.cus_code = #{code} or c.cus_service_com like #{code} )")
	public Integer selectTongCount(@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("code")String code);
	
	@Select("SELECT COUNT(*)  from erp_tire_police tp where tp.plate in (select c.car_plate from erp_customer_car c where c.customer_id =#{custId} ) and tp.police_type = #{type} and tp.police_dt >= #{startTime} and tp.police_dt <=#{endTime}")
	public Integer selecttire(@Param("custId")int custId,@Param("type")int type,@Param("startTime")String startTime,@Param("endTime")String endTime);
}
